package com.cddx.logistics.controller;

import com.cddx.logistics.domain.dto.SysAnnouncementQueryDTO;
import com.cddx.logistics.domain.vo.SysAnnouncementVO;
import com.cddx.logistics.service.SysAnnouncementService;
import com.cddx.logistics.util.model.R;
import com.cddx.logistics.util.model.Result;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@RestController
@Api(tags = "公告管理控制器")
@RequestMapping("/sysAnnouncement")
public class SysAnnouncementController {

    @Resource
    private SysAnnouncementService sysAnnouncementService;

    /**
     * 查询所有公告
     */
    @GetMapping("/queryPage")
    @ApiModelProperty("分页查询公告信息")
    public R      queryPage(SysAnnouncementQueryDTO sysAnnouncementQueryDTO){
        PageInfo<SysAnnouncementVO> pageInfo = sysAnnouncementService.queryPage(sysAnnouncementQueryDTO);
        return R.ok(pageInfo);
    }

    /**
     * 删除公告
     */
    @GetMapping("/delete")
    @ApiModelProperty("删除公告")
    public Result delete(Integer id){
        return sysAnnouncementService.delete(id);
    }

    /**
     * 批量删除
     */
    @PostMapping("/deleteAll")
    @ApiModelProperty("批量删除公告")
    public R      deleteAll(@RequestBody Map<String, List<Integer>> param) {
        List<Integer> ids = param.get("ids");
        sysAnnouncementService.deleteAll(ids);
        return R.ok();
    }

    /**
     * 全部标记已读
     */
    @PostMapping("/all")
    @ApiModelProperty("全部标记已读")
    public R      markAllAsRead() {
        sysAnnouncementService.markAllAsRead();
        return R.ok();
    }
}
